﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Linq;
using System.Text;
using System.IO;

namespace omaura_oled
{
    /// <summary>
    /// Class to get the informations of the themes
    /// - Themes list: ThemesList.txt
    /// 
    /// - Description of the theme: description.txt
    /// - Preview: preview.bmp 
    /// </summary>
    public class ReadThemes
    {
        #region "Data"
        //--
        public OmauraOled parent;
        public string[] ThemesList = new string[10];
        //--
        #endregion "Data"

        #region "Constructor"
        //--
        public ReadThemes(OmauraOled OledInterface)
        {
            parent = OledInterface;

            int i = 0;
            string line;

            #region "ReadListThemes"
            //-read
            using(StreamReader fileThemesReader = new StreamReader(".\\Resources\\Themes\\ThemesList.txt"))
            {
                while (((line = fileThemesReader.ReadLine()) != null) && i < 255)
                {

                    if (line[0] != '[')
                    {
                        ThemesList[i] = line;
                        OledInterface.listThemes.Items.Add(ThemesList[i]);
                    }
                    i++;
                }
            }
            #endregion "ReadListThemes"
        }
        //--
        #endregion "Constructor"

        #region "Methods"
        //-- 
        public void ReadPreviewTheme(string ThemeName, OmauraOled OledInterface)
        {
            string Description = "";

            using(StreamReader fileReader = new StreamReader(".\\Resources\\Themes\\" + ThemeName + "\\Description.txt"))
            {
                Description = fileReader.ReadToEnd();

                string pathTemp = OledInterface.InstallPath + "/Resources/Themes/" + ThemeName + "/Preview.bmp";
                
                //-- create the image
                BitmapImage ImageToDisplay = new BitmapImage();
                ImageToDisplay.BeginInit();
                ImageToDisplay.UriSource = new Uri(pathTemp);
                ImageToDisplay.EndInit();

                //-- display theme preview
                OledInterface.picturePreview.Source = ImageToDisplay;

                //-- display theme description
                OledInterface.textThemeComment.Text = Description;
            }
        }
        //-
        #endregion "Methods"
    }
}